<template>
  <div class="pay-item">
    <div class="item" v-for="item in dataList" :key="item.id" @click="handleClick(item)">
      <div class="info">
        <div class="lawer">
          <div class="top">
            <div class="name">
              <text v-if="item.consultation_type == 1">在线咨询</text>
              <text v-else-if="item.consultation_type == 2">电话咨询</text>
              <text v-else-if="item.consultation_type == 3">合同起草</text>
              <text v-else-if="item.consultation_type == 4">律师函</text>
            </div>
            <div class="status">
              <text v-if="item.status == 3">已关闭</text>
              <text class="nopay" v-else-if="item.status == 0">未支付</text>
              <text v-else-if="item.status == 1">已支付</text>
              <text v-else-if="item.status == 2">已完成</text>
            </div>
          </div>
          <div class="bottom">
            <div class="company">{{item.problem}}</div>
            <div class="money">￥{{item.payment_money}}</div>
          </div>
        </div>
      </div>
      <div class="btn">
        <div class="hybrid">
          <text class="lawer">{{item.reply_realname ? item.reply_realname : '未匹配律师'}}</text>
          <text>{{item.main_title}}</text>
        </div>
        <template>
          <div class="button" v-if="item.status == 0" @click.stop="handlePay(item.id)">立即支付</div>
          <div class="button" v-else-if="item.status == 1 && item.receipt_status == 0" @click.stop="handleWait(item)">待接单</div>
          <div class="button" v-else-if="item.status == 1 && item.receipt_status == 1" @click.stop="handleConfrim(item)">完成服务</div>
          <navigator
            :url="'/pageMy/menu/comment?orderid='+item.id+'&type='+type"
            class="button"
            v-else-if="item.status == 2 && !item.score"
          >评价</navigator>
        </template>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    dataList: {
      type: Array,
      default: []
    },
    type: {
      type: Number
    }
  },
  methods: {
    // 支付
    handlePay(orderid) {
      this.$gh.pay(orderid).catch(err => {
        uni.showToast({
          icon: 'none',
          title: '支付失败',
          duration: 2000
        });
      });
    },
    handleWait() {
      uni.showToast({
        icon: 'none',
        title: '律师未接单',
        duration: 2000
      });
    },
    async handleConfrim(item) {
      await this.$store.dispatch("modal", "是否确定完成服务？");
      // 请求
      const res = await this.$gh
        .request("member.order", {
          data: {
            op: "editComplete",
            orderid: item.id
          }
        })
        .catch(() => {});
      if (res.code == 200) {
        uni.navigateTo({
          url: `/pageMy/menu/comment?orderid=${item.id}&type=${this.type}&lawyerid=${item.lawyer.id}`
        });
      }
    },
    handleClick({ status, id, lawyer }) {
      status = parseInt(status);
      console.log(this.type);
      switch (status) {
        case 1:
          // 已支付
          uni.navigateTo({
            url: `/pageMy/menu/orderDetail?id=${id}&type=${this.type}&lawyerid=${lawyer.id}`
          });
          break;
        case 2:
          // 已完成
          uni.showToast({
            icon: "none",
            mask: true,
            title: "订单已完成",
            duration: 2000
          });
          break;
        case 3:
          // 已关闭
          uni.showToast({
            icon: "none",
            mask: true,
            title: "订单已关闭",
            duration: 2000
          });
          break;
      }
    }
  }
};
</script>
<style lang='less' scoped>
@import url("../../common/util.less");
.pay-item {
  padding: 25rpx 25rpx 0;
  .item {
    padding: 25rpx;
    background-color: #fff;
    border-radius: 30rpx;
    margin-bottom: 25rpx;
    .info {
      .flex();

      .lawer {
        flex: 1;
        .top {
          .gh-between();
          padding-bottom: 10rpx;
          .name {
            padding: 8rpx 14rpx;
            border-radius: 25rpx;
            background-color: @font-color;
            font-size: 24rpx;
            color: #fff;
          }

          .status {
            text {
              font-size: 24rpx;
              color: @font-color;
            }
            .nopay {
              color: red;
            }
          }
        }

        .bottom {
          .gh-between();
          .company {
            width: 75%;
            word-break: break-all;
            font-size: 30rpx;
            color: @deep-color;
          }

          .money {
            width: 25%;
            text-align: right;
            font-size: 24rpx;
            color: red;
          }
        }
      }
    }

    .btn {
      .gh-between();
      margin-top: 15rpx;
      .hybrid {
        font-size: 24rpx;
        color: @font-color;
        .lawer {
          margin-right: 15rpx;
        }
      }
      .button {
        padding: 10rpx 20rpx;
        font-size: 30rpx;
        color: #fff;
        border-radius: 30rpx;
        background-color: #849aff;
      }
    }
  }
}
</style>